import 'package:flutter_screenutil/screenutil.dart';
import 'package:flutter/material.dart';
import 'package:heyangkuaidai/DemonStrateModule/Components/TwoLabelItem.dart';
import 'package:heyangkuaidai/DemonStrateModule/Components/LeftLabelInputItem.dart';
import 'package:heyangkuaidai/DemonStrateModule/Components/SmsCodeItem.dart';
import 'package:heyangkuaidai/DemonStrateModule/Components/NavigationBar.dart';
import 'package:flutter_picker/flutter_picker.dart';
import 'package:heyangkuaidai/DemonStrateModule/Components/DateFormatUtil.dart';
import 'package:heyangkuaidai/DemonStrateModule/PreLoanSendPage.dart';
class LoanSendApplyPage extends StatefulWidget {
  @override
  _LoanSendApplyPageState createState() => _LoanSendApplyPageState();
}

class _LoanSendApplyPageState extends State<LoanSendApplyPage> {
  showPickerDateTime(BuildContext context) {
    Picker(
        adapter: DateTimePickerAdapter(
          type: PickerDateTimeType.kYMD,
          isNumberMonth: true,
          //strAMPM: const["上午", "下午"],
          yearSuffix: "年",
          monthSuffix: "月",
          daySuffix: "日",
          minValue: DateTime.now(),
          minuteInterval: 30,
          minHour: 1,
          maxHour: 23,
          // twoDigitYear: true,
        ),
        title: Text("选择日期"),
        cancelText:"取消",
        confirmText: "确定",
        textAlign: TextAlign.right,
        selectedTextStyle: TextStyle(color: Colors.blue),
        onConfirm: (Picker picker, List value) {
          setState(() {
            stateText = picker.adapter.text.substring(0,10);
          });
          print(picker.adapter.text);
        },
        onSelect: (Picker picker, int index, List<int> selecteds) {
         this. setState(() {
            stateText = picker.adapter.toString().substring(0,10);
          });
        }
    ).show(_scaffoldKey.currentState);
  }
  final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
  String stateText = "";
  DateFormatUtil format = DateFormatUtil();
  String money;
  @override
  Widget build(BuildContext context) {
   String dateNow = format.dateAndTimeToString(int.parse(DateTime.now().millisecondsSinceEpoch.toString()) ,formart: {"y-m":"-","m-d":"-"});
    ScreenUtil.init(context, width: 375, height: 667, allowFontScaling: true);
    return Scaffold(
      key: _scaffoldKey,
      resizeToAvoidBottomInset: false,
      body: Column(
        children: [
          SizedBox(height: MediaQuery.of(context).padding.top,),
          NavigationBar(false,title: "放款申请",),
          Container(
              width: ScreenUtil.screenWidth,
              height: ScreenUtil().setWidth(260),
              child: ListView(
                padding: EdgeInsets.only(top: 0),
                children: [

                  TwoLabelItem(title:"剩余额度" ,hitText:"100,000.00元 " ,),
                  TwoLabelItem(title:"合同到期日", hitText: "2022-04-30",),
                  TwoLabelItem(title:"借款日期", hitText: "2021-05-15",),
                  LeftLabelInputItem(title: "借款金额",hitText: "请输入借款金额",finishCallback: (text){
                     money =text;
                  },),
                 InkWell(
                   onTap: (){
                     showPickerDateTime(context);
                   },
                   child: TwoLabelItem(title:"到期日期", hitText: stateText.isEmpty?dateNow:stateText,showArrown: true,),
                 )
                ],
              )
          ) ,
          Container(
            width: ScreenUtil().setWidth(345),
            child:Center(
              child: Text("温馨提示\n1、单笔放款金额1000元起，以1000的整数倍递增，单笔借款最高不超过20万元。\n2、收款账号仅支持湖南省农商银行账号。\n3、每月21日为还款日，系统将从绑定账号中自动划扣。\n4、借款期限必须大于等于28天。",style: TextStyle(fontSize: ScreenUtil().setSp(12),color: Color(0xff666666)),textAlign: TextAlign.left,),
            ),
          ),
          SizedBox(height: ScreenUtil().setWidth(23),),
          InkWell(
            onTap: (){
              //标配日期
              final date2 = DateTime.now();

              //比较相差的天数
              final difference2 = DateTime.parse(stateText).difference(date2).inDays;
              String startEndDate ="2021-05-15至$stateText";
              print(difference2);
              if(difference2 >-365 && difference2 < 365 &&(money!=null||money?.isNotEmpty)) {
                Navigator.push(
                  context,
                  new MaterialPageRoute(
                    builder: (context) => new PreLoanSendPage(money: money,startEndDate:startEndDate,),
                  ),
                );

              }
            },
            child: Container(
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(4),
                  color:Color(0xff41A5EE),
                ),
                width: ScreenUtil().setWidth(347),
                height: ScreenUtil().setWidth(44),
                child:Center(
                  child: Text("下一步",style: TextStyle(fontSize: ScreenUtil().setSp(17),color: Colors.white),textAlign: TextAlign.center,),
                )
            ) ,
          )
        ],
      ),
    );
  }
}
